package com.xxxx.transformation_operator;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * @program: flink19Test
 * @description:
 * @author: CoreDao
 * @create: 2021-04-01 17:00
 **/

public class UnionOperator {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //flink为了达到高吞吐，也是通过buffer来提高吞吐量，不是一条数据就计算。
        //有界流
        env.setBufferTimeout(-1);
        env.setParallelism(1);

        List<Tuple2<String, String>> list = Arrays.asList(
                Tuple2.of("男", "小王"),
                Tuple2.of("男", "老孟"),
                Tuple2.of("男", "小张"),
                Tuple2.of("男", "老王")
        );

        List<Tuple2<String, String>> list1 = Arrays.asList(
                Tuple2.of("女", "啊哈"),
                Tuple2.of("男", "老孟"),
                Tuple2.of("女", "拉拉"),
                Tuple2.of("男", "老王")
        );




        DataStreamSource<Tuple2<String, String>> dataStreamSource = env.fromCollection(list);
        DataStreamSource<Tuple2<String, String>> dataStreamSource1 = env.fromCollection(list1);

        DataStream<Tuple2<String, String>> union = dataStreamSource.union(dataStreamSource1);
        union.print();


        env.execute();

    }
}
